package in.ac.dei.edrp.cms.controller.updateprestaging;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import in.ac.dei.edrp.cms.dao.updateprestaging.UpdatePrestagingConnect;
import in.ac.dei.edrp.cms.domain.cgpadivision.CgpaDivisionInfoGetter;
import in.ac.dei.edrp.cms.domain.studentremedial.StudentRemedialInfoGetter;
import in.ac.dei.edrp.cms.domain.updateprestaging.UpdatePrestagingInfoGetter;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class UpdatePrestagingController extends MultiActionController {
	
@SuppressWarnings("unused")
private UpdatePrestagingConnect updatePrestagingConnect;

public void setUpdatePrestagingConnect(UpdatePrestagingConnect updatePrestagingConnect) {
	this.updatePrestagingConnect = updatePrestagingConnect;
}

public ModelAndView getRecords(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
			System.out.println("Rohit Controller");
	UpdatePrestagingInfoGetter input = new UpdatePrestagingInfoGetter();

	 HttpSession session = request.getSession(true);
	 //input.setUserId(session.getAttribute("userId").toString());
	 //input.setRollNo(session.getAttribute("userName").toString());
	 //input.setUniversityCode(session.getAttribute("universityId").toString());
	 //input.setRollNo("10FSC005");
	 //setUniversityCode("DEDU");

	List<UpdatePrestagingInfoGetter> resultDetails = updatePrestagingConnect
			.getRecords(input);
	System.out.println(resultDetails.size()+"controller size");
	return new ModelAndView("UpdatePrestaging/PrestagingDetails",
			"resultObject", resultDetails);

}

/**
 * Method for deleting records(divisions)for the concerned university
 * @param request
 * @param response
 * @return String
 * @throws Exception
 */
 public ModelAndView deleteRecords(HttpServletRequest request,
     HttpServletResponse response) throws Exception {
      System.out.println("del control");
     HttpSession session = request.getSession(true);

     String userId = (String) session.getAttribute("userId");
		
		if(userId == null)
     {
     return new ModelAndView("general/SessionInactive","sessionInactive",true);
     }
		StringTokenizer rollNo =new StringTokenizer(request.getParameter("regRollNo"),"|");
		StringTokenizer entNo =new StringTokenizer(request.getParameter("newEntityId"),"|");
		StringTokenizer prgNo =new StringTokenizer(request.getParameter("newProgramId"),"|");
		StringTokenizer brnNo =new StringTokenizer(request.getParameter("newBranchId"),"|");
		StringTokenizer spcNo =new StringTokenizer(request.getParameter("newSpecializationId"),"|");
		StringTokenizer semNo =new StringTokenizer(request.getParameter("newSemesterId"),"|");
		StringTokenizer admNo =new StringTokenizer(request.getParameter("admissionMode"),"|");
		StringTokenizer atmNo =new StringTokenizer(request.getParameter("attemptNumber"),"|");
		StringTokenizer enrNo =new StringTokenizer(request.getParameter("enrollNo"),"|");
		List<UpdatePrestagingInfoGetter> inputs=new ArrayList<UpdatePrestagingInfoGetter>();
		while(rollNo.hasMoreTokens())
		{
			UpdatePrestagingInfoGetter input = new UpdatePrestagingInfoGetter();        
		    
			input.setRegRollNo(rollNo.nextToken());
			input.setNewEntityId(entNo.nextToken());
			input.setNewProgramId(prgNo.nextToken());
			input.setNewBranchId(brnNo.nextToken());
			input.setNewSpecializationId(spcNo.nextToken());
			input.setNewSemesterId(semNo.nextToken());
			input.setAdmissionMode(admNo.nextToken());
			input.setAttemptNumber(atmNo.nextToken());
			input.setEnrollNo(enrNo.nextToken());
			
			inputs.add(input);
		}
      System.out.println("delete controller");
     
     String resultDeleteDetails = updatePrestagingConnect.deletePrestagingRecords(inputs);

     return new ModelAndView("preProcessChecks/preProcessResultlist",
         "resultObject", resultDeleteDetails);
 }

 /**
  * This method is used for setting up the details for the divisions
  * on the basis of activity(insert/update)
  * @param request
  * @param response
  * @return List
  * @throws Exception
  */
 public ModelAndView updateRecords(HttpServletRequest request,
     HttpServletResponse response) throws Exception {
     UpdatePrestagingInfoGetter detail = new UpdatePrestagingInfoGetter();

     HttpSession session = request.getSession(true);

     String userId = (String) session.getAttribute("userId");
		
		if(userId == null)
     {
     return new ModelAndView("general/SessionInactive","sessionInactive",true);
     }
		System.out.println("update controller");
		detail.setUserId(userId);
		detail.setRegRollNo(request.getParameter("regRollNo"));
		detail.setEnrollNo(request.getParameter("enrollNo"));
		detail.setStudentfname(request.getParameter("studentfname"));
		detail.setStudentmname(request.getParameter("studentmname"));
		detail.setStudentlname(request.getParameter("studentlname"));
		detail.setFatherfname(request.getParameter("fatherfname"));
		detail.setFathermname(request.getParameter("fathermname"));
		detail.setFatherlname(request.getParameter("fatherlname"));
		detail.setMotherfname(request.getParameter("motherfname"));
		detail.setMothermname(request.getParameter("mothermname"));
		detail.setMotherlname(request.getParameter("motherlname"));
		detail.setPrimaryMail(request.getParameter("primaryMail"));
		detail.setDob(request.getParameter("dob"));
		detail.setGender(request.getParameter("gender"));
		detail.setCategoryId(request.getParameter("category"));
		detail.setNewEntityId(request.getParameter("newEntityId"));
		detail.setNewProgramId(request.getParameter("newProgramId"));
		detail.setNewBranchId(request.getParameter("newBranchId"));
		detail.setNewSpecializationId(request.getParameter("newSpecializationId"));
		detail.setNewSemesterId(request.getParameter("newSemesterId"));
		detail.setAttemptNumber(request.getParameter("attemptNumber"));
		detail.setAdmissionMode(request.getParameter("admissionMode"));
		detail.setProcesssedFlag(request.getParameter("processsedFlag"));
		detail.setRegistrationDueDate(request.getParameter("registrationDueDate"));
		detail.setSemesterStartDate(request.getParameter("semesterStartDate"));
		detail.setSemesterEndDate(request.getParameter("semesterEndDate"));
		detail.setProcessStatus(request.getParameter("processStatus"));
		detail.setReasoncode(request.getParameter("reasoncode"));
		detail.setDescription(request.getParameter("description"));
		detail.setPerAddress(request.getParameter("perAddress"));
		detail.setPerCity(request.getParameter("perCity"));
		detail.setPerState(request.getParameter("perState"));
		detail.setPerPincode(request.getParameter("perPincode"));
		detail.setCorAddress(request.getParameter("corAddress"));
		detail.setCorCity(request.getParameter("corCity"));
		detail.setCorState(request.getParameter("corState"));
		detail.setCorPincode(request.getParameter("corPincode"));
		detail.setOfficePhone(request.getParameter("officePhone"));
		detail.setExtraPhone(request.getParameter("extraPhone"));
		detail.setOtherPhone(request.getParameter("otherPhone"));
		detail.setFax(request.getParameter("fax"));
		detail.setUpdRegRollNo(request.getParameter("updRegRollNo"));
		detail.setUpdEnrollNo(request.getParameter("updEnrollNo"));
		detail.setUpdNewEntity(request.getParameter("updNewEntity"));
		detail.setUpdNewProgram(request.getParameter("updNewProgram"));
		detail.setUpdNewBranch(request.getParameter("updNewBranch"));
		detail.setUpdNewSpecialization(request.getParameter("updNewSpecialization"));
		detail.setUpdNewSemester(request.getParameter("updNewSemester"));
		detail.setUpdAttemptNumber(request.getParameter("updAttemptNumber"));
		detail.setUpdAdmissionMode(request.getParameter("updAdmissionMode"));


     String resultSetSuccess = updatePrestagingConnect.updatePrestagingDetails(detail);
     	System.out.println(resultSetSuccess.length()+"coming");
     return new ModelAndView("preProcessChecks/preProcessResultlist",
         "resultObject", resultSetSuccess);
 }



}
